.class public Lcom/brixd/niceapp/ui/ImageSelector;
.super Landroid/widget/RelativeLayout;
.source "ImageSelector.java"


# annotations
.annotation system Ldalvik/annotation/MemberClasses;
    value = {
        Lcom/brixd/niceapp/ui/ImageSelector$OnLoadImageEvent;
    }
.end annotation


# instance fields
.field private mAddButtonWidth:I

.field private mContext:Landroid/content/Context;

.field private mImageBorderWidth:I

.field private mImageUrls:Ljava/util/ArrayList;
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "Ljava/util/ArrayList",
            "<",
            "Lcom/brixd/niceapp/community/model/PictureModel;",
            ">;"
        }
    .end annotation
.end field

.field private mMetrics:Landroid/util/DisplayMetrics;

.field private mOnAddButtonClickListener:Landroid/view/View$OnClickListener;

.field private mOnLoadImageEvent:Lcom/brixd/niceapp/ui/ImageSelector$OnLoadImageEvent;


# direct methods
.method public constructor <init>(Landroid/content/Context;)V
    .registers 3
    .param p1, "context"    # Landroid/content/Context;

    .prologue
    .line 32
    invoke-direct {p0, p1}, Landroid/widget/RelativeLayout;-><init>(Landroid/content/Context;)V

    .line 22
    const/16 v0, 0xc8

    iput v0, p0, Lcom/brixd/niceapp/ui/ImageSelector;->mImageBorderWidth:I

    .line 23
    const/16 v0, 0x50

    iput v0, p0, Lcom/brixd/niceapp/ui/ImageSelector;->mAddButtonWidth:I

    .line 33
    invoke-direct {p0, p1}, Lcom/brixd/niceapp/ui/ImageSelector;->init(Landroid/content/Context;)V

    .line 34
    return-void
.end method

.method public constructor <init>(Landroid/content/Context;Landroid/util/AttributeSet;)V
    .registers 4
    .param p1, "context"    # Landroid/content/Context;
    .param p2, "attrs"    # Landroid/util/AttributeSet;

    .prologue
    .line 37
    invoke-direct {p0, p1, p2}, Landroid/widget/RelativeLayout;-><init>(Landroid/content/Context;Landroid/util/AttributeSet;)V

    .line 22
    const/16 v0, 0xc8

    iput v0, p0, Lcom/brixd/niceapp/ui/ImageSelector;->mImageBorderWidth:I

    .line 23
    const/16 v0, 0x50

    iput v0, p0, Lcom/brixd/niceapp/ui/ImageSelector;->mAddButtonWidth:I

    .line 38
    invoke-direct {p0, p1}, Lcom/brixd/niceapp/ui/ImageSelector;->init(Landroid/content/Context;)V

    .line 39
    return-void
.end method

.method public constructor <init>(Landroid/content/Context;Landroid/util/AttributeSet;I)V
    .registers 5
    .param p1, "context"    # Landroid/content/Context;
    .param p2, "attrs"    # Landroid/util/AttributeSet;
    .param p3, "defStyle"    # I

    .prologue
    .line 42
    invoke-direct {p0, p1, p2, p3}, Landroid/widget/RelativeLayout;-><init>(Landroid/content/Context;Landroid/util/AttributeSet;I)V

    .line 22
    const/16 v0, 0xc8

    iput v0, p0, Lcom/brixd/niceapp/ui/ImageSelector;->mImageBorderWidth:I

    .line 23
    const/16 v0, 0x50

    iput v0, p0, Lcom/brixd/niceapp/ui/ImageSelector;->mAddButtonWidth:I

    .line 43
    invoke-direct {p0, p1}, Lcom/brixd/niceapp/ui/ImageSelector;->init(Landroid/content/Context;)V

    .line 44
    return-void
.end method

.method private addAddButton()V
    .registers 5

    .prologue
    .line 123
    new-instance v0, Landroid/widget/RelativeLayout$LayoutParams;

    iget v2, p0, Lcom/brixd/niceapp/ui/ImageSelector;->mAddButtonWidth:I

    iget v3, p0, Lcom/brixd/niceapp/ui/ImageSelector;->mAddButtonWidth:I

    invoke-direct {v0, v2, v3}, Landroid/widget/RelativeLayout$LayoutParams;-><init>(II)V

    .line 124
    .local v0, "addBtnParams":Landroid/widget/RelativeLayout$LayoutParams;
    const/16 v2, 0xb

    invoke-virtual {v0, v2}, Landroid/widget/RelativeLayout$LayoutParams;->addRule(I)V

    .line 125
    const/16 v2, 0xd

    invoke-virtual {v0, v2}, Landroid/widget/RelativeLayout$LayoutParams;->addRule(I)V

    .line 126
    new-instance v1, Landroid/widget/ImageView;

    iget-object v2, p0, Lcom/brixd/niceapp/ui/ImageSelector;->mContext:Landroid/content/Context;

    invoke-direct {v1, v2}, Landroid/widget/ImageView;-><init>(Landroid/content/Context;)V

    .line 127
    .local v1, "imageView":Landroid/widget/ImageView;
    const/16 v2, 0x3e8

    invoke-virtual {v1, v2}, Landroid/widget/ImageView;->setId(I)V

    .line 128
    const/4 v2, 0x1

    invoke-virtual {v1, v2}, Landroid/widget/ImageView;->setClickable(Z)V

    .line 129
    sget-object v2, Landroid/widget/ImageView$ScaleType;->FIT_XY:Landroid/widget/ImageView$ScaleType;

    invoke-virtual {v1, v2}, Landroid/widget/ImageView;->setScaleType(Landroid/widget/ImageView$ScaleType;)V

    .line 130
    const v2, 0x7f020134

    invoke-virtual {v1, v2}, Landroid/widget/ImageView;->setImageResource(I)V

    .line 131
    new-instance v2, Lcom/brixd/niceapp/ui/ImageSelector$2;

    invoke-direct {v2, p0}, Lcom/brixd/niceapp/ui/ImageSelector$2;-><init>(Lcom/brixd/niceapp/ui/ImageSelector;)V

    invoke-virtual {v1, v2}, Landroid/widget/ImageView;->setOnTouchListener(Landroid/view/View$OnTouchListener;)V

    .line 138
    iget-object v2, p0, Lcom/brixd/niceapp/ui/ImageSelector;->mOnAddButtonClickListener:Landroid/view/View$OnClickListener;

    if-eqz v2, :cond_3f

    .line 139
    iget-object v2, p0, Lcom/brixd/niceapp/ui/ImageSelector;->mOnAddButtonClickListener:Landroid/view/View$OnClickListener;

    invoke-virtual {v1, v2}, Landroid/widget/ImageView;->setOnClickListener(Landroid/view/View$OnClickListener;)V

    .line 142
    :cond_3f
    invoke-virtual {p0, v1, v0}, Lcom/brixd/niceapp/ui/ImageSelector;->addView(Landroid/view/View;Landroid/view/ViewGroup$LayoutParams;)V

    .line 143
    return-void
.end method

.method private init(Landroid/content/Context;)V
    .registers 3
    .param p1, "context"    # Landroid/content/Context;

    .prologue
    .line 47
    iput-object p1, p0, Lcom/brixd/niceapp/ui/ImageSelector;->mContext:Landroid/content/Context;

    .line 48
    invoke-virtual {p1}, Landroid/content/Context;->getResources()Landroid/content/res/Resources;

    move-result-object v0

    invoke-virtual {v0}, Landroid/content/res/Resources;->getDisplayMetrics()Landroid/util/DisplayMetrics;

    move-result-object v0

    iput-object v0, p0, Lcom/brixd/niceapp/ui/ImageSelector;->mMetrics:Landroid/util/DisplayMetrics;

    .line 50
    return-void
.end method

.method private loadImage(Landroid/widget/ImageView;Ljava/lang/String;)V
    .registers 6
    .param p1, "imageView"    # Landroid/widget/ImageView;
    .param p2, "imageUrl"    # Ljava/lang/String;

    .prologue
    .line 146
    iget-object v1, p0, Lcom/brixd/niceapp/ui/ImageSelector;->mOnLoadImageEvent:Lcom/brixd/niceapp/ui/ImageSelector$OnLoadImageEvent;

    if-eqz v1, :cond_c

    iget-object v1, p0, Lcom/brixd/niceapp/ui/ImageSelector;->mOnLoadImageEvent:Lcom/brixd/niceapp/ui/ImageSelector$OnLoadImageEvent;

    invoke-interface {v1, p1, p2}, Lcom/brixd/niceapp/ui/ImageSelector$OnLoadImageEvent;->onLoadImage(Landroid/widget/ImageView;Ljava/lang/String;)Z

    move-result v1

    if-nez v1, :cond_26

    .line 148
    :cond_c
    :try_start_c
    new-instance v1, Ljava/lang/StringBuilder;

    invoke-direct {v1}, Ljava/lang/StringBuilder;-><init>()V

    const-string v2, "file://"

    invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    invoke-virtual {v1, p2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v1

    invoke-static {v1}, Landroid/net/Uri;->parse(Ljava/lang/String;)Landroid/net/Uri;

    move-result-object v1

    invoke-virtual {p1, v1}, Landroid/widget/ImageView;->setImageURI(Landroid/net/Uri;)V
    :try_end_26
    .catch Ljava/lang/Exception; {:try_start_c .. :try_end_26} :catch_27

    .line 155
    :cond_26
    :goto_26
    return-void

    .line 149
    :catch_27
    move-exception v0

    .line 151
    .local v0, "e":Ljava/lang/Exception;
    invoke-virtual {v0}, Ljava/lang/Exception;->printStackTrace()V

    goto :goto_26
.end method

.method private refreshViews()V
    .registers 15

    .prologue
    const/4 v11, 0x1

    const/4 v12, 0x0

    .line 58
    invoke-virtual {p0}, Lcom/brixd/niceapp/ui/ImageSelector;->removeAllViews()V

    .line 62
    const/4 v7, 0x0

    .line 63
    .local v7, "marginH":I
    const/4 v8, 0x0

    .line 64
    .local v8, "paddingH":I
    invoke-virtual {p0}, Lcom/brixd/niceapp/ui/ImageSelector;->getLayoutParams()Landroid/view/ViewGroup$LayoutParams;

    move-result-object v9

    .line 65
    .local v9, "params":Landroid/view/ViewGroup$LayoutParams;
    instance-of v10, v9, Landroid/view/ViewGroup$MarginLayoutParams;

    if-eqz v10, :cond_1a

    move-object v10, v9

    .line 66
    check-cast v10, Landroid/view/ViewGroup$MarginLayoutParams;

    iget v10, v10, Landroid/view/ViewGroup$MarginLayoutParams;->leftMargin:I

    check-cast v9, Landroid/view/ViewGroup$MarginLayoutParams;

    .end local v9    # "params":Landroid/view/ViewGroup$LayoutParams;
    iget v13, v9, Landroid/view/ViewGroup$MarginLayoutParams;->rightMargin:I

    add-int v7, v10, v13

    .line 68
    :cond_1a
    invoke-virtual {p0}, Lcom/brixd/niceapp/ui/ImageSelector;->getPaddingLeft()I

    move-result v10

    invoke-virtual {p0}, Lcom/brixd/niceapp/ui/ImageSelector;->getPaddingRight()I

    move-result v13

    add-int v8, v10, v13

    .line 70
    iget-object v10, p0, Lcom/brixd/niceapp/ui/ImageSelector;->mMetrics:Landroid/util/DisplayMetrics;

    iget v10, v10, Landroid/util/DisplayMetrics;->widthPixels:I

    sub-int/2addr v10, v7

    sub-int/2addr v10, v8

    iget v13, p0, Lcom/brixd/niceapp/ui/ImageSelector;->mAddButtonWidth:I

    sub-int v2, v10, v13

    .line 71
    .local v2, "imageContainerWidth":I
    iget-object v10, p0, Lcom/brixd/niceapp/ui/ImageSelector;->mImageUrls:Ljava/util/ArrayList;

    invoke-virtual {v10}, Ljava/util/ArrayList;->size()I

    move-result v4

    .line 72
    .local v4, "imageSize":I
    iget v10, p0, Lcom/brixd/niceapp/ui/ImageSelector;->mImageBorderWidth:I

    div-int v10, v2, v10

    if-lt v10, v4, :cond_74

    .line 73
    invoke-direct {p0}, Lcom/brixd/niceapp/ui/ImageSelector;->addAddButton()V

    .line 76
    const/4 v1, 0x0

    .local v1, "i":I
    :goto_3e
    if-ge v1, v4, :cond_cd

    .line 77
    new-instance v3, Landroid/widget/RelativeLayout$LayoutParams;

    iget v10, p0, Lcom/brixd/niceapp/ui/ImageSelector;->mImageBorderWidth:I

    iget v12, p0, Lcom/brixd/niceapp/ui/ImageSelector;->mImageBorderWidth:I

    invoke-direct {v3, v10, v12}, Landroid/widget/RelativeLayout$LayoutParams;-><init>(II)V

    .line 78
    .local v3, "imageParams":Landroid/widget/RelativeLayout$LayoutParams;
    new-instance v5, Landroid/widget/ImageView;

    iget-object v10, p0, Lcom/brixd/niceapp/ui/ImageSelector;->mContext:Landroid/content/Context;

    invoke-direct {v5, v10}, Landroid/widget/ImageView;-><init>(Landroid/content/Context;)V

    .line 79
    .local v5, "imageView":Landroid/widget/ImageView;
    sget-object v10, Landroid/widget/ImageView$ScaleType;->CENTER_CROP:Landroid/widget/ImageView$ScaleType;

    invoke-virtual {v5, v10}, Landroid/widget/ImageView;->setScaleType(Landroid/widget/ImageView$ScaleType;)V

    .line 80
    add-int/lit8 v10, v1, 0x1

    invoke-virtual {v5, v10}, Landroid/widget/ImageView;->setId(I)V

    .line 81
    if-lez v1, :cond_5f

    .line 82
    invoke-virtual {v3, v11, v1}, Landroid/widget/RelativeLayout$LayoutParams;->addRule(II)V

    .line 84
    :cond_5f
    invoke-virtual {p0, v5, v3}, Lcom/brixd/niceapp/ui/ImageSelector;->addView(Landroid/view/View;Landroid/view/ViewGroup$LayoutParams;)V

    .line 85
    iget-object v10, p0, Lcom/brixd/niceapp/ui/ImageSelector;->mImageUrls:Ljava/util/ArrayList;

    invoke-virtual {v10, v1}, Ljava/util/ArrayList;->get(I)Ljava/lang/Object;

    move-result-object v10

    check-cast v10, Lcom/brixd/niceapp/community/model/PictureModel;

    invoke-virtual {v10}, Lcom/brixd/niceapp/community/model/PictureModel;->getImageUriPath()Ljava/lang/String;

    move-result-object v10

    invoke-direct {p0, v5, v10}, Lcom/brixd/niceapp/ui/ImageSelector;->loadImage(Landroid/widget/ImageView;Ljava/lang/String;)V

    .line 76
    add-int/lit8 v1, v1, 0x1

    goto :goto_3e

    .line 88
    .end local v1    # "i":I
    .end local v3    # "imageParams":Landroid/widget/RelativeLayout$LayoutParams;
    .end local v5    # "imageView":Landroid/widget/ImageView;
    :cond_74
    invoke-direct {p0}, Lcom/brixd/niceapp/ui/ImageSelector;->addAddButton()V

    .line 91
    add-int/lit8 v1, v4, -0x1

    .restart local v1    # "i":I
    :goto_79
    if-ltz v1, :cond_cd

    .line 92
    iget v10, p0, Lcom/brixd/niceapp/ui/ImageSelector;->mImageBorderWidth:I

    sub-int v10, v2, v10

    add-int/lit8 v13, v4, -0x1

    div-int v0, v10, v13

    .line 93
    .local v0, "halfImageWidth":I
    new-instance v3, Landroid/widget/RelativeLayout$LayoutParams;

    iget v10, p0, Lcom/brixd/niceapp/ui/ImageSelector;->mImageBorderWidth:I

    iget v13, p0, Lcom/brixd/niceapp/ui/ImageSelector;->mImageBorderWidth:I

    invoke-direct {v3, v10, v13}, Landroid/widget/RelativeLayout$LayoutParams;-><init>(II)V

    .line 94
    .restart local v3    # "imageParams":Landroid/widget/RelativeLayout$LayoutParams;
    const/16 v10, 0x3e8

    invoke-virtual {v3, v12, v10}, Landroid/widget/RelativeLayout$LayoutParams;->addRule(II)V

    .line 95
    sub-int v10, v4, v1

    add-int/lit8 v10, v10, -0x1

    mul-int/2addr v10, v0

    iput v10, v3, Landroid/widget/RelativeLayout$LayoutParams;->rightMargin:I

    .line 97
    new-instance v5, Landroid/widget/ImageView;

    iget-object v10, p0, Lcom/brixd/niceapp/ui/ImageSelector;->mContext:Landroid/content/Context;

    invoke-direct {v5, v10}, Landroid/widget/ImageView;-><init>(Landroid/content/Context;)V

    .line 98
    .restart local v5    # "imageView":Landroid/widget/ImageView;
    sget-object v10, Landroid/widget/ImageView$ScaleType;->CENTER_CROP:Landroid/widget/ImageView$ScaleType;

    invoke-virtual {v5, v10}, Landroid/widget/ImageView;->setScaleType(Landroid/widget/ImageView$ScaleType;)V

    .line 99
    add-int/lit8 v10, v1, 0x1

    invoke-virtual {v5, v10}, Landroid/widget/ImageView;->setId(I)V

    .line 101
    add-int/lit8 v10, v4, -0x1

    if-ne v1, v10, :cond_cb

    move v6, v11

    .line 102
    .local v6, "isTopView":Z
    :goto_ae
    new-instance v10, Lcom/brixd/niceapp/ui/ImageSelector$1;

    invoke-direct {v10, p0, v5}, Lcom/brixd/niceapp/ui/ImageSelector$1;-><init>(Lcom/brixd/niceapp/ui/ImageSelector;Landroid/widget/ImageView;)V

    invoke-virtual {v5, v10}, Landroid/widget/ImageView;->setOnClickListener(Landroid/view/View$OnClickListener;)V

    .line 116
    invoke-virtual {p0, v5, v3}, Lcom/brixd/niceapp/ui/ImageSelector;->addView(Landroid/view/View;Landroid/view/ViewGroup$LayoutParams;)V

    .line 117
    iget-object v10, p0, Lcom/brixd/niceapp/ui/ImageSelector;->mImageUrls:Ljava/util/ArrayList;

    invoke-virtual {v10, v1}, Ljava/util/ArrayList;->get(I)Ljava/lang/Object;

    move-result-object v10

    check-cast v10, Lcom/brixd/niceapp/community/model/PictureModel;

    invoke-virtual {v10}, Lcom/brixd/niceapp/community/model/PictureModel;->getImageUriPath()Ljava/lang/String;

    move-result-object v10

    invoke-direct {p0, v5, v10}, Lcom/brixd/niceapp/ui/ImageSelector;->loadImage(Landroid/widget/ImageView;Ljava/lang/String;)V

    .line 91
    add-int/lit8 v1, v1, -0x1

    goto :goto_79

    .end local v6    # "isTopView":Z
    :cond_cb
    move v6, v12

    .line 101
    goto :goto_ae

    .line 120
    .end local v0    # "halfImageWidth":I
    .end local v3    # "imageParams":Landroid/widget/RelativeLayout$LayoutParams;
    .end local v5    # "imageView":Landroid/widget/ImageView;
    :cond_cd
    return-void
.end method


# virtual methods
.method public setImageUrls(Ljava/util/ArrayList;)V
    .registers 2
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "(",
            "Ljava/util/ArrayList",
            "<",
            "Lcom/brixd/niceapp/community/model/PictureModel;",
            ">;)V"
        }
    .end annotation

    .prologue
    .line 53
    .local p1, "imageUrls":Ljava/util/ArrayList;, "Ljava/util/ArrayList<Lcom/brixd/niceapp/community/model/PictureModel;>;"
    iput-object p1, p0, Lcom/brixd/niceapp/ui/ImageSelector;->mImageUrls:Ljava/util/ArrayList;

    .line 54
    invoke-direct {p0}, Lcom/brixd/niceapp/ui/ImageSelector;->refreshViews()V

    .line 55
    return-void
.end method

.method public setOnAddButtonClickListener(Landroid/view/View$OnClickListener;)V
    .registers 2
    .param p1, "listener"    # Landroid/view/View$OnClickListener;

    .prologue
    .line 172
    iput-object p1, p0, Lcom/brixd/niceapp/ui/ImageSelector;->mOnAddButtonClickListener:Landroid/view/View$OnClickListener;

    .line 173
    return-void
.end method

.method public setOnLoadImageEvent(Lcom/brixd/niceapp/ui/ImageSelector$OnLoadImageEvent;)V
    .registers 2
    .param p1, "event"    # Lcom/brixd/niceapp/ui/ImageSelector$OnLoadImageEvent;

    .prologue
    .line 168
    iput-object p1, p0, Lcom/brixd/niceapp/ui/ImageSelector;->mOnLoadImageEvent:Lcom/brixd/niceapp/ui/ImageSelector$OnLoadImageEvent;

    .line 169
    return-void
.end method
